<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>

                    <el-col :md="6" :sm="12">
                        <el-form-item label="名称:" prop="name.value">
                            <el-input v-model="queryParams.name.value" placeholder="请输入名称" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label='医院类型:'>
                            <el-select v-model="queryParams.type.value" placeholder='医院类型' clearable>
                                <el-option
                                    v-for='item in typeList'
                                    :key='item.value'
                                    :label='item.label'
                                    :value='item.value'>
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item label="状态:" prop="status.value">
                            <el-select v-model="queryParams.status.value" placeholder="请选择状态" clearable>
                                <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span='1.5'>
                    <el-button type='primary' plain icon='el-icon-plus' size='mini' @click='profileUpdateListShow=true' v-hasPermi='api.profile'>
                        信息更新审核
                    </el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:moreColumn>
                    <el-table-column type="expand">
                        <template slot-scope="props">
                            <el-form label-position="left" inline class="demo-table-expand">
                                <el-form-item label="医院分类">
                                    <el-tag :key="idx"
                                            v-for="(el, idx) in props.row.categorys"
                                            :disable-transitions="false">
                                        {{ [el.category1_text, el.category2_text, el.category3_text].filter(e=>!!e).join("/") }}
                                    </el-tag>
                                </el-form-item>
                                <el-form-item label="医院级别">
                                    <el-tag :key="idx"
                                            v-for="(el, idx) in props.row.levels"
                                            :disable-transitions="false">
                                        {{ [el.category1_text, el.category2_text, el.category3_text].filter(e=>!!e).join("/") }}
                                    </el-tag>
                                </el-form-item>
                                <el-form-item label="法人姓名">
                                    <span>{{ props.row.person_name }}</span>
                                </el-form-item>
                                <el-form-item label="法人身份证">
                                    <span>{{ props.row.person_idcard }}</span>
                                </el-form-item>
                                <el-form-item label="医院证件">
                                    <el-image
                                        style="width: 100px; height: 100px"
                                        :src="el"
                                        v-for="(el, idx) in props.row.certificates"
                                        :key="idx"
                                        :preview-src-list="props.row.certificates">
                                    </el-image>
                                </el-form-item>
                                <el-form-item label="所在地址">
                                    <span>{{ props.row.address }}</span>
                                </el-form-item>
                                <el-form-item label="官方网址">
                                    <span>{{ props.row.website }}</span>
                                </el-form-item>
                                <el-form-item label="咨询电话">
                                    <span>{{ props.row.service_tel }}</span>
                                </el-form-item>
                                <el-form-item label="医院优势">
                                    <span>{{ props.row.advantage }}</span>
                                </el-form-item>
                                <el-form-item label="浏览量">
                                    <span>{{ props.row.view_count }}</span>
                                </el-form-item>
                                <el-form-item label="收藏数">
                                    <span>{{ props.row.collect_num }}</span>
                                </el-form-item>
                                <el-form-item label="审核时间">
                                    <span>{{ props.row.verify_time }}</span>
                                </el-form-item>
                            </el-form>
                        </template>
                    </el-table-column>
                </template>
                <template v-slot:action>
                    <el-table-column label="操作" width="180">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                            <el-button size='mini' type='text' icon='el-icon-edit' @click='handleAdmin(scope.row)'
                                       v-hasPermi='api.edit'>管理设置
                            </el-button>
                            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>
        <!-- 编辑弹窗 -->
        <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
        <el-dialog width='60%' class="dialog-no-pd" height='90vh'  :title=" '信息更新审核'" :visible='profileUpdateListShow' append-to-body
                   :before-close='()=>{this.profileUpdateListShow=false}' destroy-on-close>
            <profileList></profileList>
        </el-dialog>
        <el-dialog width='60%' class="dialog-no-pd" height='90vh'  :title=" '管理员'" :visible='adminShow' append-to-body
                   :before-close='()=>{this.adminShow=false}' destroy-on-close>
            <admin :query-obj='{
                tenant_id: findFormData.tenant_id
            }' v-if="adminShow"></admin>
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
import profileList from './profile/index.vue'
import admin from './admin/index.vue'

export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm, profileList  , admin },
    data() {
        return {
            pk: 'id',
            adminShow:false,
            profileUpdateListShow:false,

            typeList: [
                { label: '未分类', value: 0 },
                { label: '社区医院', value: 1 },
                { label: '大医院', value: 2 },
            ],
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60,
                },
                {
                    visible: true,
                    label: 'logo',
                    prop: 'logo',
                    component:'QuickAdminImage',
                },
                {
                    visible: true,
                    label: '医院名称',
                    prop: 'name',
                },
                {
                    visible: true,
                    label: '医院类型',
                    prop: 'type',
                    component: 'QuickAdminTextColor',
                    formatter: (prop, row) => {
                        let type = ''
                        switch (prop) {
                            case 0:
                                type = 'info'
                                break
                            case 1:
                                type = 'warning'
                                break
                            case 2:
                                type = 'success'
                                break
                        }
                        return {
                            value: prop,
                            type: type,
                            text: row.type_text,
                        }
                    },
                },
                {
                    visible: true,
                    label: '统一社会信用代码',
                    prop: 'uscc',
                },
                {
                    visible: true,
                    label: '状态',
                    prop: 'status',
                    component: 'QuickAdminTextColor',
                    formatter: (prop, row) => {
                        let type = ''
                        switch (prop) {
                            case 1:
                                type = 'success'
                                break
                            case 2:
                                type = 'warning'
                                break
                            case 3:
                                type = 'info'
                                break

                        }
                        return {
                            value: prop,
                            type: type,
                            text: row.status_text,
                        }
                    },
                },
                {
                    visible: true,
                    label: '创建时间',
                    prop: 'create_time',
                    width: 120,
                    overflow: true
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                    width: 120,
                    overflow: true
                }
            ],
            // 接口地址
            api: {
                index: `/admin/ch.hospital/index`,
                find: `/admin/ch.hospital/find`,
                add: `/admin/ch.hospital/add`,
                edit: `/admin/ch.hospital/edit`,
                delete: `/admin/ch.hospital/delete`,
                export: `/admin/ch.hospital/export`,
                profile: `/admin/ch.profile/index`,
                status: `/admin/ch.hospital/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                name: { value:undefined, op: '='},
                type: { value:undefined, op: '='},
                status: { value: undefined, op: '=' },
            },
            status: [
                { label: '正常', value: 1 },
                { label: '禁用', value: 0 },
            ],
        }
    },

    methods: {
        handleAdmin(findFormData){
            if (!findFormData.tenant_id) return this.$message.error("未绑定租户")
            this.adminShow=true;
            this.findFormData=findFormData;
        }
    },
}
</script>
